struct ListNode
{
    ListNode *next;
    int val;
};

class Solution
{
public:
    ListNode *deleteNode(ListNode *head, int val)
    {
        ListNode *cur = head;
        if (head->val == val)
        {
            head = head->next;
        }
        else
        {
            while (cur->next->val != val)
            {
                cur = cur->next;
            }
            cur->next = cur->next->next;
        }
        return head;
    }
};